﻿using AutoMapper;
using MediatR;
using S.PurchaseAndSales.Api.Application.Command.PurchaseFormCommand;
using S.PurchaseAndSales.Domain.Model;
using S.PurchaseAndSales.Infrastructure.Interface.PurchaseForm;

namespace S.PurchaseAndSales.Api.Application.CommandHandlers.PurchaseFormHandler
{
    /// <summary>
    /// 采购修改
    /// </summary>
    public class PurchaseFormUpdateCommandHandler : IRequestHandler<PurchaseFormUpdateCommand, bool>
    {
        #region 注入
        private readonly IPurchaseFormRepository repository;
        private readonly IMapper mapper;

        public PurchaseFormUpdateCommandHandler(IPurchaseFormRepository repository, IMapper mapper)
        {
            this.repository = repository;
            this.mapper = mapper;
        }

        #endregion
        public async Task<bool> Handle(PurchaseFormUpdateCommand request, CancellationToken cancellationToken)
        {
            request.UpdateTime=DateTime.Now;
            return await repository.UpdateAsync(mapper.Map<PurchaseFormModel>(request));
        }
    }
}
